<?php
exit;
require_once dirname(__FILE__) . '/config.php';

//require_once dirname(__FILE__) . '/views/header.tpl.php';

?>

<pre>

<?php

// Set up the IPP instance
$IPP = new QuickBooks_IPP($dsn);

// Get our OAuth credentials from the database
$creds = $IntuitAnywhere->load($the_username, $the_tenant);

// Tell the framework to load some data from the OAuth store
$IPP->authMode(
	QuickBooks_IPP::AUTHMODE_OAUTH, 
	$the_username, 
	$creds);

// Print the credentials we're using
//print_r($creds);

// This is our current realm
$realm = $creds['qb_realm'];

// Load the OAuth information from the database
if ($Context = $IPP->context())
{
	// Set the IPP version to v3 
	$IPP->version(QuickBooks_IPP_IDS::VERSION_3);
	
	$SalesReceiptService = new QuickBooks_IPP_Service_SalesReceipt();
	
	$SalesReceipt = new QuickBooks_IPP_Object_SalesReceipt();
	
	$SalesReceipt->setDocNumber('WEB' . mt_rand(0, 10000));
	$SalesReceipt->setTxnDate('2013-10-11');
	
	
	
	$SalesReceipt->setPaymentRefNum("1000");
	$SalesReceipt->setPaymentMethodRef("3");
	
	$Billemail =new QuickBooks_IPP_Object_BillEmail();
	$Billemail->setEmailStatus('NeedToSend');
	//$Billemail->setIsToBeEmailed(true);
	$Billemail->setAddress('kanij.citrusbug@gmail.com');
	
	
	$Line = new QuickBooks_IPP_Object_Line();
	$Line->setDetailType('SalesItemLineDetail');
	//$Line->setEmail('kanij.citrusbug@gmail.com');
	$Line->setAmount(12.95 * 2);
	$Line->setDescription('Test description goes here.');
	
	$SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
	$SalesItemLineDetail->setItemRef('1');
	
	$SalesItemLineDetail->setUnitPrice(12.95);
	$SalesItemLineDetail->setQty(2);

	$Line->addSalesItemLineDetail($SalesItemLineDetail);

	$SalesReceipt->addLine($Line);
	
	$SalesReceipt->addBillEmail($Billemail);
	
	//$SalesReceipt->addIsToBeEmailed(true);
	
	$SalesReceipt->setCustomerRef('1');
	$SalesReceipt->setCustomerMemo('Total includes all applicable taxes.');

	

	if ($resp = $SalesReceiptService->add($Context, $realm, $SalesReceipt))
	{
		print('Our new SalesReceiptService ID is: [' . $resp . ']');
	}
	else
	{
		print($SalesReceiptService->lastError());
	}
	
	
	/*print('<pre>');
	print('Request [' . $IPP->lastRequest() . ']');
	print('=======');
	print('Response [' . $IPP->lastResponse() . ']');
	print("\n\n\n\n\n\n\n\n\n");
	*/
}
else
{
	die('Unable to load a context...?');
}


?>

</pre>

<?php

//require_once dirname(__FILE__) . '/views/footer.tpl.php';
